/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package apt;

import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author PhiNguyen
 */
public class TableModel extends AbstractTableModel{
    private ArrayList<String> colNames;
    private ArrayList<SinhVien> data;

    public TableModel() {
    }

    public TableModel(ArrayList<String> colNames, ArrayList<SinhVien> data) {
        this.colNames = colNames;
        this.data = data;
    }

    @Override
    public int getRowCount() {
        return data.size();
    }

    @Override
    public int getColumnCount() {
        return colNames.size();
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        SinhVien sv = data.get(rowIndex);
        int idTmp = sv.getID();
        String nameTmp = sv.getName();
        String mailTmp = sv.getMail();
        String phoneTmp = sv.getPhone();
        if (columnIndex == 0) {
            return idTmp;
        }
        if (columnIndex == 1) {
            return nameTmp;
        }
        if (columnIndex == 2) {
            return mailTmp;
        }
        if (columnIndex == 3) {
            return phoneTmp;
        }
        return "";
    }

    @Override
    public String getColumnName(int column) {
        String columnTmp = colNames.get(column);
        return columnTmp;
    }
    public SinhVien getSinhVienAtRow(int rowIndex){
        SinhVien sv = data.get(rowIndex);
        return sv;
    }
    
    
    
}
